import datetime

import django_filters
from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from loguru import logger
from rest_framework.filters import BaseFilterBackend

<<<<<<< HEAD
from .models import Order

# 订单筛选器
class OrderFilter(django_filters.rest_framework.FilterSet):
    # 订单号
    ordernum = django_filters.CharFilter(lookup_expr="icontains")
    # 订单日期时间
    OrderDtm = django_filters.CharFilter(method="filter_OrderDtm")

    def filter_OrderDtm(self, queryset, name, value):
        """根据发药具体日期时间段筛选"""
        return queryset.filter(order_date__range=value.split(","))

=======
from apps.Order.models import Order


# 药方
class OrderFilter(django_filters.rest_framework.FilterSet):
    # 订单编号
    ordernum = django_filters.CharFilter(lookup_expr="icontains")
    # 发药日期时间
    orderdate = django_filters.CharFilter(method="filter_OrderDate")
    # 根据是否有效
    is_active = django_filters.BooleanFilter(field_name="is_active",lookup_expr="exact")
    # 根据人员筛选
    user_id = django_filters.CharFilter(method="filter_user_id")

    def filter_OrderDate(self, queryset, name, value):
        """根据订单日期时间段筛选"""
        return queryset.filter(order_date__range=value.split(","))

    def filter_user_id(self, queryset, name, value):
        """根据人员筛选"""
        return queryset.filter(staruser__id=value)

>>>>>>> dev
    class Meta:
        model = Order
        fields = "__all__"
